﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyCourseManageProject.Model;
using MyCourseManageProject.Bll;

namespace MyCourseManageProject.UI
{
    public partial class FrmModifyPwd : Form
    {
        public FrmModifyPwd()
        {
            InitializeComponent();
        }
        TeachersBll tbll = new TeachersBll();
        /// <summary>
        /// 提交修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            string oldPwd = this.txtPwd.Text.Trim();
            string newPwd = this.txtNwePwd.Text.Trim();
            string newPwd2 = this.txtNwePwd2.Text.Trim();

            string msg;
            Teachers teacher = new Teachers()
            {
                LoginPwd = oldPwd,
                LoginAccount = Program.currentTeacher.LoginAccount
            };
            if (string.IsNullOrEmpty(oldPwd) || string.IsNullOrEmpty(newPwd) || string.IsNullOrEmpty(newPwd2))
            {
                MessageBox.Show("密码不能为空,请补充信息");
                return;
            }
            Teachers th = tbll.TeacherLogin(teacher);
            if (th == null)
            {
                MessageBox.Show("密码输入错误,请重新输入", "提示信息");
                this.txtPwd.Text = "";
                this.txtPwd.Focus();//获取焦点
            }
            else
            {
                if (newPwd == newPwd2)
                {
                    teacher.LoginPwd = newPwd;
                    bool isOk = tbll.Update(teacher, out msg);
                    if (isOk)
                    {
                        MessageBox.Show(msg, "提示信息");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(msg, "提示信息");

                        this.txtNwePwd.Text = "";
                        this.txtNwePwd2.Text = "";
                        this.txtNwePwd.Focus();//获取焦点
                    }
                }
                else
                {
                    MessageBox.Show("两次密码输入不一致,请重新输入", "提示信息");
                    this.txtNwePwd.Text = "";
                    this.txtNwePwd2.Text = "";
                    this.txtNwePwd.Focus();//获取焦点
                }
            }
           



        }
        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
